import time

import ImageProc
import ADBHelper
import RaphaelScriptHelper as RS
from settings import *

REFRESH_TIME = 5  # s


class Img:
    screen = './cache/screenCap.png'
    fight = './img/Fight.jpg'

    class Fight:
        start_game = './img/Fight-startGame.png'
        back = './img/Fight-back.png'
        not_enough = ''
        jingying = './img/jy.png'
        class Skil:
            gun_子弹命中怪物后爆炸 = './img/Fight-skill-gun-baozha.png'
            gun_每次射击连发数加1 = './img/Fight-skill-gun-lianfashuliang.png'
            gun_子弹弹道数量加1 = './img/Fight-skill-gun-zidanshuliang.png'
            gun_将子弹变为火焰子弹 = './img/Fight_skill_gun_huoyanzidan.png'

            gun = './img/Fight-gun.png'
            fire_燃烧油桶 = './img/Fight-burnOil.png'
            car_车 = './img/Fight-car.png'
            boom = './img/Fight-boom.png'
            wind = './img/Fight-wind.png'
            air_boom = './img/Fight-airBoom.png'
            light = './img/Fight-light.png'
            guided_laser = './img/Fight-guidedLaser.png'
            air_knife = './img/Fight-airKnife.png'
            ice_bullet = './img/Fight-iceBullet.png'
            drop_down = './img/Fight-dropDown.png'
            diancicichuan = './img/Fight-diancicichuan.png'
            bingbaofashengqi = './img/Fight-bingbaofashengqi.png'
            yueqiandianzi = './img/Fight-yueqiandianzi.png'
            wurenjichongji = './img/Fight-wurenjichongji.png'
            dianjizhu = './img/Fight-dianjizhu.png'

            start_game = './img/Fight-startGame.jpg'
            back = './img/Fight-back.png'

            # blood = './img/Fight-blood.png'
            skill_first = [
                gun_子弹命中怪物后爆炸,     #1
                gun_每次射击连发数加1,      #2
                gun_子弹弹道数量加1,        #3
                gun_将子弹变为火焰子弹,     #4
                gun,                        #5
                fire_燃烧油桶,              #6
                dianjizhu,                  #7
                wind,                       #8
                car_车,                     #9
                light,                      #10
                boom,                       #11
                wurenjichongji,             #12
                air_boom,                   #13
                guided_laser,               #14
                air_knife,                  #15
                ice_bullet,                 #16
                diancicichuan,              #17
                bingbaofashengqi,           #18
                yueqiandianzi,              #19
                drop_down
            ]

def weight_list():
    list_1 = [20]
    list_gun = [1, 2, 3, 4, 5]#指向列表中的位置
    list_ice = [18, 16]
    list_fire = [11, 6]
    list_wind = [15, 8, 13]
    list_phy = [9, 12]
    list_power = [14, 10]
    list_e = [17, 19]
    sorted_items = list_ice + list_gun + list_fire + list_phy + list_e + list_wind + list_power #根据技能排序，也可以把列表改成优先级列表
    return (sorted_items)
def is_game_over():
    return False


def have_play_advertisement():
    return False


def play_game(play_num=1):


    # 刷新屏幕
    ADBHelper.screenCapture(device, Img.screen)

    # return
    start = ImageProc.locate(Img.screen, Img.Fight.start_game)
    RS.suiji(start)
    time.sleep(REFRESH_TIME * 3)
    # if point:
    #     ADBHelper.touch(device, point)
    cash_order = weight_list()
    while not ImageProc.locate(Img.screen, Img.Fight.back):

        ADBHelper.screenCapture(device, Img.screen)
        jy = ImageProc.locate(Img.screen, Img.Fight.jingying)
        if jy:
            RS.suiji(jy)
            time.sleep(3)
            RS.suiji(jy)

        for cash in cash_order:
            point = ImageProc.locate(Img.screen, Img.Fight.Skil.skill_first[cash - 1])
            if point:
                print(point)
                RS.suiji(point)
                break


        time.sleep(REFRESH_TIME)
    esc = ImageProc.locate(Img.screen, Img.Fight.back)
    RS.suiji(esc)
    time.sleep(REFRESH_TIME * 1.5)

if __name__ == '__main__':
    device = ADBHelper.getDevicesList()[0]
    print(f'当前连接的设备是: {device}')
    for _ in range(60):
        play_game()

    # print(f'{Img.Fight.startGame}')
